<?php

class PropostaController extends Zend_Controller_Action
{
    /**
     * @var Application_Model_Propostas 
     */
    protected $_propostas;
    
    /**
     * @var Application_Model_Categorys
     */
    protected $_categorys;

    public function init()
    {
        // Breadcrumbs configuration
        $uri = $this->_request->getPathInfo();
        $activeNav = $this->view->navigation()->findByUri($uri);
        if ($activeNav) { // Controllo per evitare "Strict standards: Creating default object from empty value"
            $activeNav->active = true;
        }
        
        $this->_propostas = new Application_Model_Propostas();
        $this->_categorys = new Application_Model_Categorys();
    }

    public function indexAction()
    {
        $page = $this->_getParam('page', 1);
        
        $proposte = $this->_propostas->getAllPropostas($page, 'propTitolo asc');
        
        $this->view->proposte = $proposte;
        
        // Setup serch form
        $searchForm = new Application_Form_SearchPropForm();
        $searchForm->setAction('/search/search-proposte');
        $this->view->searchForm = $searchForm;
    }
    
    public function showbycatAction()
    {
        $catIdent = $this->_getParam('catIdent');
        $cat = $this->_categorys->getCategoryByIdent($catIdent);
        $this->view->titoloCategoria = $cat->catNome;
        
        // Prendo le proposte della categoria
        $catId = $cat->catId;
        $propostas = $this->_propostas->getPropostasByCategoryId($catId);
        $this->view->propostas = $propostas;
    }
    
    public function showAction()
    {
        $propIdent = $this->_getParam('propIdent');
        $proposta = $this->_propostas->getPropostaByIdent($propIdent);
        $this->view->proposta = $proposta;
    }

    public function noproposteAction() 
    {
        
    }

    public function sitemapAction()
    {
        $this->view->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        echo $this->view->navigation()->sitemap();
    }
}

